package com.ogawa.a7517.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.example.reslib.utils.PreferenceWrapper;
import com.ogawa.a7517.Constant;
import com.ogawa.a7517.R;
import com.ogawa.a7517.adapter.LeadAdapter;

public class LeadPageFragment extends BaseFragment {

    @Override
    public int getLayoutId() {
        return R.layout.fragment_lead_page;
    }

    @Override
    public void initView(View view) {
        ViewPager vpLead = view.findViewById(R.id.vp_lead);
        LeadAdapter adapter = new LeadAdapter();
        TextView tvExperience = view.findViewById(R.id.tv_experience);
        tvExperience.setOnClickListener(view1 -> {
            new PreferenceWrapper().setBooleanValueAndCommit(Constant.FIRST_IN, false);
            activity7517.popBackStack();
            activity7517.startToFragmentAddToStack(new MainFragment());
        });
        ImageView ivPoint1 = view.findViewById(R.id.iv_point_1);
        ImageView ivPoint2 = view.findViewById(R.id.iv_point_2);
        ImageView ivPoint3 = view.findViewById(R.id.iv_point_3);
        ImageView ivPoint4 = view.findViewById(R.id.iv_point_4);
        vpLead.setAdapter(adapter);
        vpLead.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                tvExperience.setVisibility(position == 3 ? View.VISIBLE : View.GONE);
                ivPoint1.setSelected(position == 0);
                ivPoint2.setSelected(position == 1);
                ivPoint3.setSelected(position == 2);
                ivPoint4.setSelected(position == 3);
            }
        });
    }
}
